export default {
	methods: {
		FormatRichText(html) { //控制小程序中图片大小
			let newContent = html.replace(/<video[^>]*>/gi, function(match, capture) {
				match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
				match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
				match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
				return match;
			}).replace(/<img[^>]*>/gi, function(match, capture) {
				match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
				match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
				match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
				return match;
			});
			newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
				match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
					'max-width:100%;');
				return match;
			});
			newContent = newContent.replace(/<br[^>]*\/>/gi, '');
			newContent = newContent.replace(/\<video/gi,
				'<video style="max-width:100%;height:auto;display:inline-block;margin:2px auto;"').replace(
				/\<img/gi,
				'<img style="max-width:100%;height:auto;display:inline-block;margin:2rpx auto;"');
			return newContent;
		},
		GoImgDetials(e) {

			let item = e.detail.node;
			if (item.name == "img") {
				uni.previewImage({
					urls: [item.attrs.src],
					longPressActions: {
						// itemList: ["保存到相册", "识别二维码"],
						itemList: ["保存到相册"],
						itemColor: "#007AFF",
						success: function(data) {
							let {
								tapIndex,
								index
							} = data;
							// tapIndex 第几个按钮
							// index 第几张图片
							//#ifdef APP-PLUS
							if (tapIndex == 0) {
								// 保存到相册
								plus.gallery.save(item.attrs.src, () => {
									uni.showToast({
										icon: "none",
										title: "保存成功!"
									})
								}, () => {
									uni.showToast({
										icon: "none",
										title: "保存失败!"
									})
								})

							} else {
								// 现将文件下载到本地
								uni.downloadFile({
									url: item.attrs.src,
									success: (args) => {
										// 扫描二维码
										plus.barcode.scan(
											args.tempFilePath,
											(code, url) => {
												// 如果识别成功
												if (code == 0) {
													// 打开扫描结果
													plus.runtime.openURL(url)
												}
											},
											(err) => {
												uni.showToast({
													icon: 'none',
													title: "图中没有可识别的二维码"
												})
												console.log(err, 'err');
											},
											[plus.barcode.QR],
											true)
									},
									fail: () => {

									}
								})
							}
							//#endif
						}
					}
				})
			}
		}
	}
}